// 防抖函数
export const debounce = function (fn, delay) {
  let timer = null;
  return function () {
    timer && clearTimeout(timer);
    let _this = this;
    let args = arguments;

    timer = setTimeout(() => {
      fn.apply(_this, args)
    }, delay);
  }
}

// 节流函数
export const throttle = function (fn, delay) {
  let timer = null;
  return function () {
    if (timer) return

    let _this = this
    let args = arguments

    timer = setTimeout(function () {
      fn.apply(_this, args)
      timer = null
    }, delay);
  }
}
